Link to this headingCSRF (Cross Side Request Forgery)
Link to this headingSimple Requests
- uses GET, HEAD or POST method
- doesn’t have headers other than the small subset defined in the specification (any custom or Authorization header breaks this condition)
- the only allowed values for Content-Type header are application/x-www-form-urlencoded, multipart/form-data, text/plain (application/json breaks this condition)
Attacks:
Using an img tag and using the href will make a simple get request to the server with the users cookies.
Using a form post will allow a post to the website with Content-Type header of application/x-www-form-urlencoded.
Usign the Navagator.sendBeacon() allows the bypass of allowing the Content-Type application/json to be used with a simple request.
Link to this headingPreflighted Requests
Sends an additional preliminary OPTIONS request (“preflight request”) in order to determine whether the actual request (“preflighted request”) is safe to send.
Example Preflight Request:
Example Preflight Response:
Performance note: sending a preflight request every time can be a performance overhead. This can be mitigated by caching preflight requests using Access-Control-Max-Age response header.
Link to this headingTesting CORS
Add a Custom Origin header and see if a HEAD request returns Access-Control-Allow-Origin or Access-Control-Allow-Credentials headers
curl --head -s 'http://example.com/api/v1/secret' -H 'Origin: http://evil.com'
Check to see what the server responds with in the Access-Control-Allow-Origin: (if anything) and if so, check if Access-Control-Allow-Credentials: true is present.
Link to this headingPoC
If it is trusting arbitrary origins with allow-credentials set to true, then host this HTML as a proof of concept.
XMLHttpRequest PoC:
Fetch Cross Domain File Upload PoC:
Test jQuery CORS:
Link to this headingCross-Domain timing
Using Cross Domain loads and monitoring the time it takes to load the page can tell if the user is logged in or not.
Using Cross Domain loads and monitoring the time it takes to retrieve the page can tell if the user has recently been on that page and is in the cache.
Using Cross Domain loads and with the onload and onerror handlers can see if user is logged in to the website.
For a GET request, a good bet is the tag plus the onerror() / onload() events.
For a POST request, you can direct the post to an <iframe> element and monitor the onload() event.
Example:
Link to this headingCross-Domain CSS
Using Cross Domain CSS and monitoring the CSS values that are different when the user is signed in.
If you are logged in, you’ll see “3px” vs. “0px” otherwise.